package com.dis.service.mapper;

import com.dis.pojo.entity.ChronicDisease;
import com.dis.pojo.queryDTO.ChronicDiseasePageQueryDTO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ChronicDiseaseMapper {

    /**
     * 新增慢性病
     * @param chronicDisease
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into chronic_disease(disease_name, icd_code, description, symptoms, treatment, prevention, is_deleted, create_time, update_time) " +
            "values(#{diseaseName}, #{icdCode}, #{description}, #{symptoms}, #{treatment}, #{prevention}, #{isDeleted}, #{createTime}, #{updateTime})")
    void insert(ChronicDisease chronicDisease);

    /**
     * 慢性病分页查询
     * @param chronicDiseasePageQueryDTO
     * @return
     */
    Page<ChronicDisease> pageQuery(ChronicDiseasePageQueryDTO chronicDiseasePageQueryDTO);

    /**
     * 根据ID查询慢性病
     * @param id
     * @return
     */
    @Select("select * from chronic_disease where id = #{id}")
    ChronicDisease getById(Long id);

    /**
     * 更新慢性病信息
     * @param chronicDisease
     */
    void update(ChronicDisease chronicDisease);

    /**
     * 根据ID删除慢性病(逻辑删除)
     * @param id
     */
    @Update("update chronic_disease set is_deleted = 1, update_time = now() where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据ID查询所属的病种类型Id
     * @param id
     * @return
     */
    @Select("select type_id from chronic_disease_type_relation where disease_id = #{id}")
    Long getTypeId(Long id);
}
